package cn.his2.masterdata.controller;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
@RefreshScope
public class DemoController {
    @Value("${server.port}")
    private int port;
    @Value("${user.password}")
    private String password;

    @GetMapping("")
    public String hello(HttpServletRequest request) {
        log.debug("master-data log message");
        log.info("master-data info message");
        log.warn("master-data warn message");
        log.debug("Authorization:", request.getHeader("Authorization"));

        return "Hello 基础数据: " + port +"," + password;
    }

    @GetMapping("/users")
    public Object users() {
        Map<Integer, User> map = new HashMap<>();
        map.put(1, new User(1, "张三", "男"));
        map.put(2, new User(2, "李四", "女"));
        return map;
    }

    @Data
    @AllArgsConstructor
    private static class User {
        private Integer id;
        private String name;
        private String gender;
    }
}
